********Figure E.2********

*Load data
cd "$reploc/data/created_data"
use mex_full, clear

*Do these results for primary sample
sort pid_link mxfls
foreach var of varlist rbuc_nga grbrprovAvg_lam0co3 grbrprovSD_lam0co3 inflation{
gen `var'dif=`var'-`var'[_n-1] if mxfls==3 & pid_link==pid_link[_n-1]
}

gen coh_prov_clust=yearprov

gen primarysample1=0
replace primarysample1=1 if rbuc_ngadif!=. & grbrprovAvg_lam0co3dif!=. & grbrprovSD_lam0co3dif!=. & inflationdif!=. &  birthyr>=1925 & coh_prov_clust!=.

egen primarysample=total(primarysample1), by(pid_link)

drop if mxfls==.
keep if panel==1
keep if primarysample==1

*Add how many people per birth province
keep if mxfls==3
gen popi=1
collapse (sum) popi, by(birthstate)

rename birthstate idmxflsstate
tempfile bprovpopsmex
save "`bprovpopsmex'", replace

cd "$reploc/data/shpfiles"
shp2dta using mexstates, database(mexdb) coordinates(mexcoord) genid(id) gencentroids(cent) replace

use mexdb.dta, clear


*Change to state id
gen idmxflsstate=.
replace idmxflsstate=1 if ADMIN_NAME=="Aguascalientes"
replace idmxflsstate=2 if ADMIN_NAME=="Baja California"
replace idmxflsstate=3 if ADMIN_NAME=="Baja California Sur"
replace idmxflsstate=4 if ADMIN_NAME=="Campeche"
replace idmxflsstate=5 if ADMIN_NAME=="Coahuila"
replace idmxflsstate=6 if ADMIN_NAME=="Colima"
replace idmxflsstate=7 if ADMIN_NAME=="Chiapas"
replace idmxflsstate=8 if ADMIN_NAME=="Chihuahua"
replace idmxflsstate=9 if ADMIN_NAME=="Distrito Federal"
replace idmxflsstate=10 if ADMIN_NAME=="Durango"
replace idmxflsstate=11 if ADMIN_NAME=="Guanajuato"
replace idmxflsstate=12 if ADMIN_NAME=="Guerrero"
replace idmxflsstate=13 if ADMIN_NAME=="Hidalgo"
replace idmxflsstate=14 if ADMIN_NAME=="Jalisco"
replace idmxflsstate=15 if ADMIN_NAME=="Mexico"
replace idmxflsstate=16 if ADMIN_NAME=="Michoacan"
replace idmxflsstate=17 if ADMIN_NAME=="Morelos"
replace idmxflsstate=18 if ADMIN_NAME=="Nayarit"
replace idmxflsstate=19 if ADMIN_NAME=="Nuevo Leon"
replace idmxflsstate=20 if ADMIN_NAME=="Oaxaca"
replace idmxflsstate=21 if ADMIN_NAME=="Puebla"
replace idmxflsstate=22 if ADMIN_NAME=="Queretaro"
replace idmxflsstate=23 if ADMIN_NAME=="Quintana Roo"
replace idmxflsstate=24 if ADMIN_NAME=="San Luis Potosi"
replace idmxflsstate=25 if ADMIN_NAME=="Sinaloa"
replace idmxflsstate=26 if ADMIN_NAME=="Sonora"
replace idmxflsstate=27 if ADMIN_NAME=="Tabasco"
replace idmxflsstate=28 if ADMIN_NAME=="Tamaulipas"
replace idmxflsstate=29 if ADMIN_NAME=="Tlaxcala"
replace idmxflsstate=30 if ADMIN_NAME=="Veracruz"
replace idmxflsstate=31 if ADMIN_NAME=="Yucatan"
replace idmxflsstate=32 if ADMIN_NAME=="Zacatecas"

merge 1:1 idmxflsstate using "`bprovpopsmex'"
tostring popi, gen(popstring_lb)
sum popi, d
local maxi=r(max)

*Adjusting where population appears on map
replace x_cent=x_cent+0.32 if idmxflsstate==3
replace y_cent=y_cent+0.15 if idmxflsstate==27
replace x_cent=x_cent+0.25 if idmxflsstate==19
replace y_cent=y_cent-0.35 if idmxflsstate==30
replace x_cent=x_cent-0.2 if idmxflsstate==30
replace y_cent=y_cent-0.35 if idmxflsstate==21
replace y_cent=y_cent-0.45 if idmxflsstate==17
replace x_cent=x_cent-0.5 if idmxflsstate==17
replace y_cent=y_cent-0.3 if idmxflsstate==15
replace x_cent=x_cent-0.25 if idmxflsstate==15
replace y_cent=y_cent+0.3 if idmxflsstate==9
replace x_cent=x_cent-0.6 if idmxflsstate==9

cd "$reploc/data/shpfiles"
spmap popi using mexcoord if popi>0, id(id) fcolor(BrBG)  label(xcoord(x_cent) ycoord(y_cent) label(popstring_lb) color(blue) size(*0.9)) clmethod(custom) clbreaks(0 239 `maxi')  legend(label(1 "No Data") label(2 "Other Birth Provinces") label(3 "MXFLS Provinces"))

cd "$reploc/results"
graph export FigureE2.eps, replace



